package com.weixin.paleituo.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.adapter.SelectCityRecyclewAdapter;
import com.weixin.paleituo.adapter.SelectConnunityMenuRecyclerViewAdapter;
import com.weixin.paleituo.base.BaseActivity;
import com.weixin.paleituo.bean.CityBean;
import com.weixin.paleituo.eventbus.SelectHouseEvent;
import com.weixin.paleituo.view.RecyclerViewCityDecoration;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 选择社区
 */
public class SelectCommunityActivity extends BaseActivity {


    @BindView(R.id.iv_back_activity_basepersoninfo)
    ImageView mIvBackActivityBasepersoninfo;
    @BindView(R.id.tv_title_activity_baseperson)
    TextView mTvTitleActivityBaseperson;
    @BindView(R.id.tv_small_title_layout_head)
    TextView mTvSmallTitleLayoutHead;
    @BindView(R.id.rl_head_root_activity_baseperson)
    RelativeLayout mRlHeadRootActivityBaseperson;
    @BindView(R.id.iv_search_head)
    ImageView mIvSearchHead;
    @BindView(R.id.edit_search_head)
    EditText mEditSearchHead;
    @BindView(R.id.tv_location_city_activity_select_commmunity)
    TextView mTvLocationCityActivitySelectCommmunity;
    @BindView(R.id.id_recyclerview_menu_activity_select_community)
    RecyclerView mRecycleActivitySelectCommunity;
    @BindView(R.id.recycler_view)
    RecyclerView mRecycleActivitySelectCity;
    private SelectConnunityMenuRecyclerViewAdapter mSelectConnunityMenuRecyclerViewAdapter;
    private SelectCityRecyclewAdapter mSelectCityRecyclewAdapter;
    private List<CityBean> mCityBeans;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_select_community);

    }

    @Override
    protected void initData() {
        super.initData();
        mTvTitleActivityBaseperson.setText("选择社区");
        mEditSearchHead.setHint("请输入小区名称");
        List<String> stringList=new ArrayList<>();
        stringList.add("全部");
        stringList.add("天府新区");
        mSelectConnunityMenuRecyclerViewAdapter = new SelectConnunityMenuRecyclerViewAdapter(this,stringList);
        mRecycleActivitySelectCommunity.setLayoutManager(new LinearLayoutManager(this));
        mRecycleActivitySelectCommunity.setItemAnimator(new DefaultItemAnimator());

        mRecycleActivitySelectCommunity.setAdapter(mSelectConnunityMenuRecyclerViewAdapter);


        mSelectConnunityMenuRecyclerViewAdapter.setOnListener(new SelectConnunityMenuRecyclerViewAdapter.OnListener() {
            @Override
            public void onItemOnClick(int position) {
                mSelectConnunityMenuRecyclerViewAdapter.setSelectPosition(position);
                mSelectConnunityMenuRecyclerViewAdapter.notifyDataSetChanged();

            }
        });


        mCityBeans = new ArrayList<>();
        CityBean cityBean=new CityBean();
        cityBean.setCityName("金南园");
        cityBean.setSpell("j");
        mCityBeans.add(cityBean);

        mSelectCityRecyclewAdapter = new SelectCityRecyclewAdapter(this, mCityBeans);

        mRecycleActivitySelectCity.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

        mRecycleActivitySelectCity.addItemDecoration(new RecyclerViewCityDecoration(this, mCityBeans));

        mRecycleActivitySelectCity.setAdapter(mSelectCityRecyclewAdapter);
        mSelectCityRecyclewAdapter.setOnListener(new SelectCityRecyclewAdapter.OnListener() {
            @Override
            public void onItemClick(int positon) {
                EventBus.getDefault().post(new SelectHouseEvent(mCityBeans.get(positon).getCityName(),2));
                SelectBuildingActivity.myStartyActvity(SelectCommunityActivity.this);
            }
        });





    }

    public static void myStartActivity(Context context) {
        Intent intent = new Intent(context, SelectCommunityActivity.class);
        context.startActivity(intent);
    }



    @OnClick(R.id.iv_back_activity_basepersoninfo)
    public void onMIvBackActivityBasepersoninfoClicked() {
        finish();
    }

}
